package cn.wolfcode.trip.app.controller;


import cn.wolfcode.trip.base.domain.ShoppingCart;
import cn.wolfcode.trip.base.service.IShoppingCartService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/** tiger
 *
 * 查询购物车商品控制器
 */
@RestController
@RequestMapping("/shoppingcarts")
public class ShoppingCartController {

    @Autowired
    private IShoppingCartService shoppingCartService;

    /**
     * 获取购物车信息
     * @param ids
     * @return
     */
    @GetMapping("{ids}")
    public PageInfo getShoppingCartById(@PathVariable int[] ids){
        List<ShoppingCart> list=shoppingCartService.getShoppingCartById(ids);
        return new PageInfo<>(list);
    }

    /**
     * 批量删除购物车信息
     * @param ids
     * @return
     */
    @DeleteMapping("{ids}")
    public JSONResult deleteShoppingCartById(@PathVariable int[] ids){
        JSONResult jsonResult= new JSONResult();
        try {
            shoppingCartService.deleteShoppingCartById(ids);
        } catch (Exception e) {
            jsonResult.mark("操作失败,稍后再试");
            e.printStackTrace();
        }
        return jsonResult;
    }
}
